Telegram Group & Telegram Channel
📱 How to: оптимизировать работу с API в мобильных приложениях

Проблема: Долгая загрузка данных, лишние запросы и падение приложения при плохом интернете.

1️⃣ Кеширование данных

Используйте Room (Android) или CoreData (iOS) для локального хранения:

// Android + Kotlin  
@Dao
interface UserDao {
@Query("SELECT * FROM users")
fun getUsers(): Flow<List<User>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveUsers(users: List<User>)
}

// iOS + Swift  
func saveUsers(_ users: [User]) {
let context = persistentContainer.viewContext
users.forEach { user in
let entity = UserEntity(context: context)
entity.id = user.id
entity.name = user.name
}
try? context.save()
}


2️⃣ Пагинация

Делите данные на страницы:

🔵 Android: Paging 3 + RemoteMediator
🔵 iOS: UICollectionViewDiffableDataSource + async/await

3️⃣ Повтор запросов при ошибках

// iOS  
func fetchWithRetry(maxAttempts: Int = 3) async throws -> Data {
for attempt in 1...maxAttempts {
do {
return try await fetchData()
} catch {
if attempt == maxAttempts { throw error }
try await Task.sleep(nanoseconds: 1_000_000_000 * UInt64(attempt))
}
}
fatalError("Unreachable")
}


4️⃣ Оптимизация JSON

🔵 Используйте kotlinx.serialization (Android) и Codable (iOS)
🔵 Исключайте ненужные поля через @Transient / @Ignore

5️⃣ HTTP-кеширование

// Android + OkHttp  
val client = OkHttpClient.Builder()
.cache(Cache(cacheDir, 10 * 1024 * 1024)) // 10 MB
.build()


💬 Как вы оптимизируете работу в своих проектах? Делитесь опытом

🐸 Библиотека мобильного разработчика

#буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/mobileproglib/5826
Create:
Last Update:

📱 How to: оптимизировать работу с API в мобильных приложениях

Проблема: Долгая загрузка данных, лишние запросы и падение приложения при плохом интернете.

1️⃣ Кеширование данных

Используйте Room (Android) или CoreData (iOS) для локального хранения:

// Android + Kotlin  
@Dao
interface UserDao {
@Query("SELECT * FROM users")
fun getUsers(): Flow<List<User>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveUsers(users: List<User>)
}

// iOS + Swift  
func saveUsers(_ users: [User]) {
let context = persistentContainer.viewContext
users.forEach { user in
let entity = UserEntity(context: context)
entity.id = user.id
entity.name = user.name
}
try? context.save()
}


2️⃣ Пагинация

Делите данные на страницы:

🔵 Android: Paging 3 + RemoteMediator
🔵 iOS: UICollectionViewDiffableDataSource + async/await

3️⃣ Повтор запросов при ошибках

// iOS  
func fetchWithRetry(maxAttempts: Int = 3) async throws -> Data {
for attempt in 1...maxAttempts {
do {
return try await fetchData()
} catch {
if attempt == maxAttempts { throw error }
try await Task.sleep(nanoseconds: 1_000_000_000 * UInt64(attempt))
}
}
fatalError("Unreachable")
}


4️⃣ Оптимизация JSON

🔵 Используйте kotlinx.serialization (Android) и Codable (iOS)
🔵 Исключайте ненужные поля через @Transient / @Ignore

5️⃣ HTTP-кеширование

// Android + OkHttp  
val client = OkHttpClient.Builder()
.cache(Cache(cacheDir, 10 * 1024 * 1024)) // 10 MB
.build()


💬 Как вы оптимизируете работу в своих проектах? Делитесь опытом

🐸 Библиотека мобильного разработчика

#буст

BY Библиотека мобильного разработчика | Android, iOS, Swift, Retrofit, Moshi, Chuck




Share with your friend now:
tg-me.com/mobileproglib/5826

View MORE
Open in Telegram


Библиотека мобильного разработчика | Android iOS Swift Retrofit Moshi Chuck Telegram | DID YOU KNOW?

Date: |

The lead from Wall Street offers little clarity as the major averages opened lower on Friday and then bounced back and forth across the unchanged line, finally finishing mixed and little changed.The Dow added 33.18 points or 0.10 percent to finish at 34,798.00, while the NASDAQ eased 4.54 points or 0.03 percent to close at 15,047.70 and the S&P 500 rose 6.50 points or 0.15 percent to end at 4,455.48. For the week, the Dow rose 0.6 percent, the NASDAQ added 0.1 percent and the S&P gained 0.5 percent.The lackluster performance on Wall Street came on uncertainty about the outlook for the markets following recent volatility.

Telegram and Signal Havens for Right-Wing Extremists

Since the violent storming of Capitol Hill and subsequent ban of former U.S. President Donald Trump from Facebook and Twitter, the removal of Parler from Amazon’s servers, and the de-platforming of incendiary right-wing content, messaging services Telegram and Signal have seen a deluge of new users. In January alone, Telegram reported 90 million new accounts. Its founder, Pavel Durov, described this as “the largest digital migration in human history.” Signal reportedly doubled its user base to 40 million people and became the most downloaded app in 70 countries. The two services rely on encryption to protect the privacy of user communication, which has made them popular with protesters seeking to conceal their identities against repressive governments in places like Belarus, Hong Kong, and Iran. But the same encryption technology has also made them a favored communication tool for criminals and terrorist groups, including al Qaeda and the Islamic State.

Библиотека мобильного разработчика | Android iOS Swift Retrofit Moshi Chuck from ms


Telegram Библиотека мобильного разработчика | Android, iOS, Swift, Retrofit, Moshi, Chuck
FROM USA